<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Schema::create('sys_user', function (Blueprint $table) {
        //     $table->comment('用户信息表');
        //     $table->bigInteger('user_id', true)->comment('用户ID');
        //     $table->bigInteger('dept_id')->nullable()->comment('部门ID');
        //     $table->string('user_name', 30)->comment('用户账号');
        //     $table->string('nick_name', 30)->comment('用户昵称');
        //     $table->string('user_type', 2)->nullable()->default('00')->comment('用户类型（00系统用户）');
        //     $table->string('email', 50)->nullable()->default('')->comment('用户邮箱');
        //     $table->string('phonenumber', 11)->nullable()->default('')->comment('手机号码');
        //     $table->char('sex', 1)->nullable()->default('0')->comment('用户性别（0男 1女 2未知）');
        //     $table->string('avatar', 100)->nullable()->default('')->comment('头像地址');
        //     $table->string('password', 100)->nullable()->default('')->comment('密码');
        //     $table->char('status', 1)->nullable()->default('0')->comment('帐号状态（0正常 1停用）');
        //     $table->char('del_flag', 1)->nullable()->default('0')->comment('删除标志（0代表存在 2代表删除）');
        //     $table->string('login_ip', 128)->nullable()->default('')->comment('最后登录IP');
        //     $table->dateTime('login_date')->nullable()->comment('最后登录时间');
        //     $table->string('create_by', 64)->nullable()->default('')->comment('创建者');
        //     $table->dateTime('create_time')->nullable()->comment('创建时间');
        //     $table->string('update_by', 64)->nullable()->default('')->comment('更新者');
        //     $table->dateTime('update_time')->nullable()->comment('更新时间');
        //     $table->string('remark', 500)->nullable()->comment('备注');
        // });
        Schema::create('sys_role', function (Blueprint $table) {
            $table->comment('角色信息表');
            $table->bigInteger('role_id', true)->comment('角色ID');
            $table->string('role_name', 30)->comment('角色名称');
            $table->string('role_key', 100)->comment('角色权限字符串');
            $table->integer('role_sort')->comment('显示顺序');
            $table->char('data_scope', 1)->nullable()->default('1')->comment('数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限）');
            $table->boolean('menu_check_strictly')->nullable()->default(true)->comment('菜单树选择项是否关联显示');
            $table->boolean('dept_check_strictly')->nullable()->default(true)->comment('部门树选择项是否关联显示');
            $table->char('status', 1)->comment('角色状态（0正常 1停用）');
            $table->char('del_flag', 1)->nullable()->default('0')->comment('删除标志（0代表存在 2代表删除）');
            $table->string('create_by', 64)->nullable()->default('')->comment('创建者');
            $table->dateTime('create_time')->nullable()->comment('创建时间');
            $table->string('update_by', 64)->nullable()->default('')->comment('更新者');
            $table->dateTime('update_time')->nullable()->comment('更新时间');
            $table->string('remark', 500)->nullable()->comment('备注');
        });
        Schema::create('sys_dept', function (Blueprint $table) {
            $table->comment('部门表');
            $table->bigInteger('dept_id', true)->comment('部门id');
            $table->bigInteger('parent_id')->nullable()->default(0)->comment('父部门id');
            $table->string('ancestors', 50)->nullable()->default('')->comment('祖级列表');
            $table->string('dept_name', 30)->nullable()->default('')->comment('部门名称');
            $table->integer('order_num')->nullable()->default(0)->comment('显示顺序');
            $table->string('leader', 20)->nullable()->comment('负责人');
            $table->string('phone', 11)->nullable()->comment('联系电话');
            $table->string('email', 50)->nullable()->comment('邮箱');
            $table->char('status', 1)->nullable()->default('0')->comment('部门状态（0正常 1停用）');
            $table->char('del_flag', 1)->nullable()->default('0')->comment('删除标志（0代表存在 2代表删除）');
            $table->string('create_by', 64)->nullable()->default('')->comment('创建者');
            $table->dateTime('create_time')->nullable()->comment('创建时间');
            $table->string('update_by', 64)->nullable()->default('')->comment('更新者');
            $table->dateTime('update_time')->nullable()->comment('更新时间');
        });
        Schema::create('sys_post', function (Blueprint $table) {
            $table->comment('岗位信息表');
            $table->bigInteger('post_id', true)->comment('岗位ID');
            $table->string('post_code', 64)->comment('岗位编码');
            $table->string('post_name', 50)->comment('岗位名称');
            $table->integer('post_sort')->comment('显示顺序');
            $table->char('status', 1)->comment('状态（0正常 1停用）');
            $table->string('create_by', 64)->nullable()->default('')->comment('创建者');
            $table->dateTime('create_time')->nullable()->comment('创建时间');
            $table->string('update_by', 64)->nullable()->default('')->comment('更新者');
            $table->dateTime('update_time')->nullable()->comment('更新时间');
            $table->string('remark', 500)->nullable()->comment('备注');
        });
        Schema::create('sys_menu', function (Blueprint $table) {
            $table->comment('菜单权限表');
            $table->bigInteger('menu_id', true)->comment('菜单ID');
            $table->string('menu_name', 50)->comment('菜单名称');
            $table->bigInteger('parent_id')->nullable()->default(0)->comment('父菜单ID');
            $table->integer('order_num')->nullable()->default(0)->comment('显示顺序');
            $table->string('path', 200)->nullable()->default('')->comment('路由地址');
            $table->string('component')->nullable()->comment('组件路径');
            $table->string('query')->nullable()->comment('路由参数');
            $table->integer('is_frame')->nullable()->default(1)->comment('是否为外链（0是 1否）');
            $table->integer('is_cache')->nullable()->default(0)->comment('是否缓存（0缓存 1不缓存）');
            $table->char('menu_type', 1)->nullable()->default('')->comment('菜单类型（M目录 C菜单 F按钮）');
            $table->char('visible', 1)->nullable()->default('0')->comment('菜单状态（0显示 1隐藏）');
            $table->char('status', 1)->nullable()->default('0')->comment('菜单状态（0正常 1停用）');
            $table->string('perms', 100)->nullable()->comment('权限标识');
            $table->string('icon', 100)->nullable()->default('#')->comment('菜单图标');
            $table->string('create_by', 64)->nullable()->default('')->comment('创建者');
            $table->dateTime('create_time')->nullable()->comment('创建时间');
            $table->string('update_by', 64)->nullable()->default('')->comment('更新者');
            $table->dateTime('update_time')->nullable()->comment('更新时间');
            $table->string('remark', 500)->nullable()->default('')->comment('备注');
        });
        Schema::create('sys_role_dept', function (Blueprint $table) {
            $table->comment('角色和部门关联表');
            $table->bigInteger('role_id')->comment('角色ID');
            $table->bigInteger('dept_id')->comment('部门ID');

            $table->primary(['role_id', 'dept_id']);
        });
        Schema::create('sys_role_menu', function (Blueprint $table) {
            $table->comment('角色和菜单关联表');
            $table->bigInteger('role_id')->comment('角色ID');
            $table->bigInteger('menu_id')->comment('菜单ID');

            $table->primary(['role_id', 'menu_id']);
        });
        Schema::create('sys_user_post', function (Blueprint $table) {
            $table->comment('用户与岗位关联表');
            $table->bigInteger('user_id')->comment('用户ID');
            $table->bigInteger('post_id')->comment('岗位ID');

            $table->primary(['user_id', 'post_id']);
        });
        Schema::create('sys_user_role', function (Blueprint $table) {
            $table->comment('用户和角色关联表');
            $table->bigInteger('user_id')->comment('用户ID');
            $table->bigInteger('role_id')->comment('角色ID');

            $table->primary(['user_id', 'role_id']);
        });
        Schema::create('sys_logininfor', function (Blueprint $table) {
            $table->comment('系统访问记录');
            $table->bigInteger('info_id', true)->comment('访问ID');
            $table->string('user_name', 50)->nullable()->default('')->comment('用户账号');
            $table->string('ipaddr', 128)->nullable()->default('')->comment('登录IP地址');
            $table->string('login_location')->nullable()->default('')->comment('登录地点');
            $table->string('browser', 50)->nullable()->default('')->comment('浏览器类型');
            $table->string('os', 50)->nullable()->default('')->comment('操作系统');
            $table->char('status', 1)->nullable()->default('0')->comment('登录状态（0成功 1失败）');
            $table->string('msg')->nullable()->default('')->comment('提示消息');
            $table->dateTime('login_time')->nullable()->comment('访问时间');
        });
        Schema::create('sys_oper_log', function (Blueprint $table) {
            $table->comment('操作日志记录');
            $table->bigInteger('oper_id', true)->comment('日志主键');
            $table->string('title', 50)->nullable()->default('')->comment('模块标题');
            $table->integer('business_type')->nullable()->default(0)->comment('业务类型（0其它 1新增 2修改 3删除）');
            $table->string('method', 100)->nullable()->default('')->comment('方法名称');
            $table->string('request_method', 10)->nullable()->default('')->comment('请求方式');
            $table->integer('operator_type')->nullable()->default(0)->comment('操作类别（0其它 1后台用户 2手机端用户）');
            $table->string('oper_name', 50)->nullable()->default('')->comment('操作人员');
            $table->string('dept_name', 50)->nullable()->default('')->comment('部门名称');
            $table->string('oper_url')->nullable()->default('')->comment('请求URL');
            $table->string('oper_ip', 128)->nullable()->default('')->comment('主机地址');
            $table->string('oper_location')->nullable()->default('')->comment('操作地点');
            $table->string('oper_param', 2000)->nullable()->default('')->comment('请求参数');
            $table->string('json_result', 2000)->nullable()->default('')->comment('返回参数');
            $table->integer('status')->nullable()->default(0)->comment('操作状态（0正常 1异常）');
            $table->string('error_msg', 2000)->nullable()->default('')->comment('错误消息');
            $table->dateTime('oper_time')->nullable()->comment('操作时间');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sys_user');
        Schema::dropIfExists('sys_role');
        Schema::dropIfExists('sys_dept');
        Schema::dropIfExists('sys_post');
        Schema::dropIfExists('sys_menu');
        Schema::dropIfExists('sys_role_dept');
        Schema::dropIfExists('sys_role_menu');
        Schema::dropIfExists('sys_user_post');
        Schema::dropIfExists('sys_user_role');
        Schema::dropIfExists('sys_logininfor');
        Schema::dropIfExists('sys_oper_log');
    }
};
